package dao

import "database/sql"

type Comment struct {
	Id  int64 `gorm:"autoIncrement,primaryKey"`
	Uid int64 `gorm:"index:uid"`
	// 你评论的是什么:帖子，视频
	Biz   string `gorm:"index:biz_id"`
	BizId int64  `gorm:"column:biz_id;index:biz_id"`

	// 顶级评论
	RootID sql.NullInt64 `gorm:"column:root_id;index:root_id_ctime"`
	// 父评论
	PID sql.NullInt64 `gorm:"column:pid;index"`
	// 外键 用于级联删除
	ParentComment *Comment `gorm:"ForeignKey:PID;AssociationForeignKey:ID;constraint:OnDelete:CASCADE"`

	Content string

	Ctime int64 `gorm:"index:root_id_ctime"`
}

// foreign key(pid) references comment(id) on delete cascade
func (*Comment) TableName() string {
	return "comment"
}
